package cn.service.impl;

import cn.mapper.HealthOrderPersonMapper;
import cn.pojo.HealthOrderPerson;
import cn.pojo.dto.OrderVaccineUser;
import cn.service.HealthOrderPersonService;
import cn.utils.BaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthOrderPersonServiceImpl implements HealthOrderPersonService {
    @Autowired
    private HealthOrderPersonMapper personMapper;
    @Override
    public Map<String, Object> save(HealthOrderPerson person) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            person.setOrderNoP(BaseUtils.getOrderNo(person.getOrderKindP()));
            ok = personMapper.save(person) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> update(HealthOrderPerson person) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = personMapper.update(person) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> delete(String id, String no) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = personMapper.delete(id, no) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> select(String userid, String kind) {
        Map<String, Object> res = new HashMap<>();
        try {
            List<OrderVaccineUser> result = personMapper.select(userid, kind);
            if (result.size() > 0) {
                res.put("msg", result);
            }else {
                res.put("msg", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            res.put("msg", false);
        }
        return res;
    }
}
